<template>
  <div class="app-container">
    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->
    <ht-search-form
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :beforeSearchCallback="false"
      @beforeSearchCallback="beforeSearchCallback"
      :clearCallBack="clearCallBack"
    >
      <template slot="endSlotOption">
        <amount-range-search label="金额区间" ref="amountRangeSearch"></amount-range-search>
      </template>
    </ht-search-form>
    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center  :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="130px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>基本信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原交易/原批次流水号" prop="oriId">
                <el-input v-model="detailForm.oriId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原报文标识号" prop="oriPkgid">
                <el-input v-model="detailForm.oriPkgid" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原报文类型" prop="oriPkgtype">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriPkgtype === null || detailForm.oriPkgtype === undefined
                      ? ''
                      : detailForm.oriPkgtype + '-' + detailForm.oriPkgtypeDesc
                  "
                  placeholder="原业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原系统编号" prop="oriSysCode">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.oriSysCode"
                  placeholder="原系统编号"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in dictMap.SYS_CODE_310_312"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原工作日期" prop="oriWorkdate">
                <el-date-picker
                  v-model="detailForm.oriWorkdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原发起参与机构" prop="oriPayerStBrno">
                <el-input v-model="detailForm.oriPayerStBrno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原付款清算行行名称" prop="oriPayerStBrname">
                <el-input v-model="detailForm.oriPayerStBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原接收参与机构" prop="oriPayeeStBrno">
                <el-input v-model="detailForm.oriPayeeStBrno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原收款清算行行名称" prop="oriPayeeStBrname">
                <el-input v-model="detailForm.oriPayeeStBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>行内处理状态</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原业务类型" prop="oriBiztype">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriBiztype === null || detailForm.oriBiztype === undefined
                      ? ''
                      : detailForm.oriBiztype + '-' + detailForm.oriBiztypeDesc
                  "
                  placeholder="原业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="this.sysCode !== 'BEPS'">
              <el-form-item label="原业务种类" prop="oriBizctgy">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriBizctgy === null || detailForm.oriBizctgy === undefined
                      ? ''
                      : detailForm.oriBizctgy + '-' + detailForm.oriBizctgyDesc
                  "
                  placeholder="原业务种类"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原交易货币" prop="oriCurcd">
                <el-input v-model="detailForm.oriCurcd" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原金额" prop="oriAmount">
                <ht-amount-input v-model="detailForm.oriAmount" placeholder="原金额" :disable="true"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="通讯状态" prop="status">
                <el-select style="width: 100%" v-model="detailForm.status" placeholder="通讯状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.COM_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select style="width: 100%" v-model="detailForm.procStatus" placeholder="中心状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" v-model="detailForm.remarks" maxlength="105" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>

      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submit" v-loading.fullscreen.lock="loading">撤 销</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { apiUrlConfigEntryQuery, businessUndoEntryDetail, businessUndoEntryDetailSave } from "@/api/cnaps/ccms/307";
import { listPageMixin } from "@/libs/listPageMixin";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import HtAmountInput from "@/views/components/HtAmountInput";
import AmountRangeSearch from "@/views/components/AmountSearchInput";
export default {
  name: "BusinessUndoEntry",
  mixins: [listPageMixin],
  components: { HtAmountInput, AmountRangeSearch },
  data() {
    return {
      // 查询参数
      queryParams: {
        id: undefined,
        beginTime: undefined,
        endTime: undefined,
        minAmt: undefined,
        maxAmt: undefined,
        sysNo: "HVPS",
      },
      sysCode: undefined,
      // 搜索
      formOptions: [],
      //
      searchFormDictList: [
        "DRCTCODE",
        "TRANS_TYPE",
        "REE_CHG_INFO",
        "SYS_CODE_310_312",
        "PROCESSSTATUS",
        "SYS_CODE",
        "COM_STATUS",
      ],
      // 列信息
      regConfig: apiUrlConfigEntryQuery,
      tableBindColumns: [
        { prop: "oriId", label: "原交易/原批次流水号", width: 180 },
        { prop: "oriSysCode", label: "原系统编号", dictCode: "SYS_CODE", width: 180, sortable: false },
        { prop: "oriWorkdate", label: "原工作日期", type: "date", width: 180 },
        {
          prop: "oriPkgtype",
          label: "原报文类型",
          formatter(row, text, index) {
            return (
              (row["oriPkgtype"] === null || row["oriPkgtype"] === undefined ? "" : row["oriPkgtype"]) +
              "-" +
              (row["oriPkgtypeDesc"] === null || row["oriPkgtypeDesc"] === undefined ? "" : row["oriPkgtypeDesc"])
            );
          },
          width: 260,
        },
        {
          prop: "oriBiztype",
          label: "原业务类型",
          formatter(row, text, index) {
            return (
              (row["oriBiztype"] === null || row["oriBiztype"] === undefined ? "" : row["oriBiztype"]) +
              "-" +
              (row["oriBiztypeDesc"] === null || row["oriBiztypeDesc"] === undefined ? "" : row["oriBiztypeDesc"])
            );
          },
          width: 180,
        },
        {
          prop: "oriBizctgy",
          label: "原业务种类",
          formatter(row, text, index) {
            return (
              (row["oriBizctgy"] === null || row["oriBizctgy"] === undefined ? "" : row["oriBizctgy"]) +
              "-" +
              (row["oriBizctgyDesc"] === null || row["oriBizctgyDesc"] === undefined ? "" : row["oriBizctgyDesc"])
            );
          },
          width: 180,
        },
        { prop: "oriPayerStBrno", label: "原发起参与机构", width: 180 },
        { prop: "oriPayeeStBrno", label: "原接收参与机构", width: 180 },
        {
          prop: "oriAmount",
          label: "原金额",
          type: "price",
          width: 150,
        },
        { prop: "procStatus", label: "中心状态", dictCode: "PROCESSSTATUS" },
      ],
      loading: false,
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        amount: 0.0,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    this.$refs.amountRangeSearch.$on('getAmountRange',this.beforeSearchCallback);

    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "原交易/批次流水号",
          placeholder: "请输入原交易/批次流水号",
        },
      },
      {
        type: "dict",
        dict: "SYS_CODE_310_312",
        prop: "sysNo",
        defaultAttr: {
          size: "small",
          label: "系统编号",
          placeholder: "请输入系统编号",
          disCleanable: true,
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "beginTime",
          endTimeName: "endTime",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务撤销申请录入明细";
      businessUndoEntryDetail(row).then((response) => {
        this.resetForm("detailForm");
        this.detailForm = response.result.map;
        this.$set(this, "sysCode", response.result.sysCode);
        this.open = true;
      });
    },

    transStatusChange() {
      const transStatus = this.detailForm.transStatus;
      if (transStatus === "TA04" || transStatus === "TA05") {
        this.$set(this.rules.reeChgInfo[0], "required", true);
      } else {
        this.$set(this.rules.reeChgInfo[0], "required", false);
      }

      const reeChgInfo = this.detailForm.reeChgInfo;
      if (reeChgInfo === "RC07") {
        this.$set(this.rules.procInfo[0], "required", true);
      } else {
        this.$set(this.rules.procInfo[0], "required", false);
      }
    },

    //点击提交按钮
    submit: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          businessUndoEntryDetailSave(this.detailForm, this.sysCode)
            .then((response) => {
              this.msgSuccess("撤销成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //点击重置按钮
    refresh() {
      this.resetForm("detailForm");
    },

    beforeSearchCallback() {
      // 搜索按钮之前先执行
      this.queryParams.minAmt = this.$refs.amountRangeSearch.getAmount1();
      this.queryParams.maxAmt = this.$refs.amountRangeSearch.getAmount2();
    },
    clearCallBack() {
      let that = this;
      return new Promise(function (resolve, reject) {
        that.$refs.amountRangeSearch.clearAmount();
        that.queryParams.minAmt = "";
        that.queryParams.maxAmt = "";
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
